﻿using System;
using System.Globalization;
using System.Windows.Forms;

namespace LDSProject.Forms
{
    public partial class SyncTimeSetForm : Form
    {
        public SyncTimeSetForm()
        {
            InitializeComponent();
        }

        private void SyncTimeSetForm_Load(object sender, EventArgs e)
        {
            var type = Properties.Settings.Default.SyncTimeType;

            if (cbType.Items.Count <= type || type < 0)
            {
                type = 0;
                Properties.Settings.Default.SyncTimeType = 0;
                Properties.Settings.Default.Save();
            }

            cbType.SelectedIndex = type;

            lbNextTime.Text = MainConsole.Instance.NextSyncTime.ToString(CultureInfo.InvariantCulture);
        }

        private void btnSet_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.SyncTimeType = cbType.SelectedIndex;
            Properties.Settings.Default.Save();

            MainConsole.Instance.SetNextSyncTime(cbType.SelectedIndex);

            Close();
        }
    }
}
